<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="referrer" content="never">
    <title>Document</title>
    <script src="../application/vue.js"></script>
    <style>
        img{
            width:300px;
            height:300px;
            border:1px solid black;
            background-color:rgba(0,0,0,0.1);
        }
    </style>
</head>
<body>
    <div id="app">
        <img v-preload:fill="img1">
        <img v-preload:cover="img2">
        <img v-preload:scale-down="img3">
    </div>
    <hr>
    <div id="root">
        <img v-preload:scale-down="img1">
    </div>
</body>
<script>
    Vue.directive("preload",function(el,binding){
        el.style.objectFit="none";
        el.style.objectPosition="center";
        el.src="../image/5-121204193935-51.gif";
        var img=new Image();
        img.src=binding.value;
        // console.log(binding.value);
        img.onload=function(){
            el.src=binding.value;
            el.style.objectFit=binding.arg
        }
    })
    var vm=new Vue({
        el:"#app",
        data:{
            img1:"https://img4q.duitang.com/uploads/item/201505/06/20150506202234_thzKj.jpeg",
            img2:"http://img5.imgtn.bdimg.com/it/u=1684654909,2180152882&fm=26&gp=0.jpg",
            img3:"http://pic40.nipic.com/20140412/11412826_124950636000_2.jpg"
        }
    })
    var vm1=new Vue({
        el:"#root",
        data:{
            img1:"https://img4q.duitang.com/uploads/item/201505/06/20150506202234_thzKj.jpeg"
        }
    })
</script>
</html>